package offer.algorithm;

import datastructure.search.BinarySearch;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/27 15:26
 */
public class NumOfKey38 {

    public static int getNumsOfkey(Integer[] array, Integer key) {
        if (array == null || array.length <= 0)
            return 0;
        int firstKIndex = BinarySearch.getFirstKIndex(array, 0, array.length - 1, key);
        if (firstKIndex == -1)
            return 0;
        int lastKIndex = BinarySearch.getLastKIndex(array, 0, array.length - 1, key);
        return lastKIndex - firstKIndex + 1;
    }
}